clear

	local b = 0
	foreach c in  5 7 8 9 {
	local b = `b' +1

	* Identify model with best fit
		forvalues v =1(1)5 {
			qui: insheet using "${data}v`c'_Parameters_`v'.csv"
			qui: destring v7, replace force
			qui: destring v8, replace force

			qui: su v7 if _n ==1
			qui: global lv`v' : di %4.1f `r(mean)'
			qui: su v8 if _n ==1
			qui: global flag`v' = `r(mean)'

			qui: clear
		}
		qui:set obs 5
		qui:ge loss =.
		qui:ge flag =.

		qui:ge sim = _n
		forvalues v =1(1)5 {
		qui: replace loss = ${lv`v'} if sim == `v'
		qui: replace flag = ${flag`v'} if sim == `v'
		}
		gsort loss sim
		su sim if _n ==1
		global best1 =   `r(mean)'


		clear
		
	
		
		
		* Moment fit
		insheet using "${data}v`c'_Moments_all_${best1}.csv"
		
	


	forvalues l = 1(1)23{
	su v1 if _n ==`l'
	local r`l'_c`b' : di %4.3f `r(mean)'
	}

	
	clear
	

	display "Here I am :  version `c'"
}


forvalues l = 1(1)23 {
	foreach z in 2 3 4 {
		local r`l'_c`z'_z : di %4.3f `r`l'_c`z'' - `r`l'_c1'
		if `r`l'_c`z'_z' >=0 {
			local r`l'_c`z'_c = "+ `r`l'_c`z'_z'"
		}
		if `r`l'_c`z'_z' <0 {
			local r`l'_c`z'_c = " `r`l'_c`z'_z'"
		}
		}
	}

	

	#delimit ;	
	file open myfile using "${output}TableA14.tex", write replace;
	file write myfile   _n "\begin{tabular}{lcccc}"			
	_n "\thickhline"
	_n "Simulated Moments &  Main model & Experiment 1   & Experiment 2   & Experiment 3 \\"
		_n " &  (1) & (2)   & (3)    & (4)  \\"

	_n "\hline"		
	_n "\mbox{}\\"
	_n " Supervisor effort in worker incentives group & `r5_c1' & `r5_c2' (`r5_c2_c')  & `r5_c3' (`r5_c3_c' ) & `r5_c4' (`r5_c4_c' ) \\ "	
	_n " Supervisor effort in supervisor incentives group		    &`r6_c1'    & `r6_c2' (`r6_c2_c') & `r6_c3' (`r6_c3_c') & `r6_c4' (`r6_c4_c')  \\ "
	_n " Supervisor effort in shared incentives group  & `r7_c1'  & `r7_c2' (`r7_c2_c' ) & `r7_c3' (`r7_c3_c') & `r7_c4' (`r7_c4_c')  \\ "	
	_n " Supervisor effort in control group   &`r8_c1' & `r8_c2' (`r8_c2_c')& `r8_c3' (`r8_c3_c' ) & `r8_c4' (`r8_c4_c' )  \\	"
	_n " Worker effort in worker incentives group & `r1_c1' & `r1_c2' (`r1_c2_c' )  & `r1_c3' (`r1_c3_c') & `r1_c4' (`r1_c4_c') \\ "	
	_n " Worker  effort in supervisor incentives group		    &`r2_c1'  & `r2_c2' (`r2_c2_c' ) & `r2_c3'  (`r2_c3_c' ) & `r2_c4'  (`r2_c4_c' ) \\ "
	_n " Worker  effort in shared incentives group  & `r3_c1'  & `r3_c2' (`r3_c2_c') & `r3_c3' (`r3_c3_c'  ) & `r3_c4' (`r3_c4_c'  ) \\ "	
	_n " Worker  effort in control group   &`r4_c1' & `r4_c2' (`r4_c2_c')  & `r4_c3' (`r4_c3_c') & `r4_c4' (`r4_c4_c')  \\	"
	_n " Output in worker incentives group & `r9_c1'  & `r9_c2' (`r9_c2_c') & `r9_c3' (`r9_c3_c') & `r9_c4' (`r9_c4_c')  \\ "	
	_n " Output in supervisor incentives group 	    &`r10_c1' & `r10_c2' (`r10_c2_c' ) & `r10_c3' (`r10_c3_c' ) & `r10_c4' (`r10_c4_c' ) \\	"
	_n " Output in shared incentives group & `r11_c1'  & `r11_c2' (`r11_c2_c') & `r11_c3' (`r11_c3_c' ) & `r11_c4' (`r11_c4_c' ) \\ "	
	_n " Output in control group 	    &`r12_c1' & `r12_c2' (`r12_c2_c') & `r12_c3' (`r12_c3_c' ) & `r12_c4' (`r12_c4_c' )   \\	"
	_n " \mbox{}\\"
	_n "\thickhline"
	_n "\end{tabular}" 
	_n " \mbox{}\\" 
	_n "\footnotesize"
	_n " Notes: The table shows simulated moments for our headline model (column 1) and for three counterfactual experiments (column 2, 3 and 4). The difference between a moment simulated in the experiment and the relative moment from our headline model is reported in parenthesis. In the first experiment, the principal forces the worker to raise the reporting threshold in all groups to the level used in \$T_{worker}\$. In the second experiment, the principal eliminates under-reporting, by forcing the worker to raise the reporting threshold in all groups to a level that guarantees 100 percent reporting.  In the third experiment, the principal reduces the mean of the cost distribution by 50 percent, by shifting downwards the upper parameter of the uniform distribution. The changes simulated in the counterfactual experiment are common knowledge among agents. ";
	file close myfile;
	#delimit cr
	
	
